<?php
class fbwidget extends CWidget
{
	
    public function run()
    {
    //header('P3P: CP="CAO PSA OUR"'); ob_start(); session_start();
		$config = array(
    			'appId' => '173271229456237',
    			'secret' => '604042cf852163b2fad38e1ec1d51a3e',
  			);

  
  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();
  echo  $user_id;
    if($user_id) {
    
      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {                                               

        $user_profile = $facebook->api('/me','GET');
              $me = $facebook->api('/me');
        //echo "Name: " . $user_profile['name'];
       // echo $user_profile['first_name'] . " " . $user_profile['last_name'] ."<br/>";
        //echo $user_profile['email'];
        //echo "<pre>";
        //print_r($user_profile);
        
      if($me){
       echo  "<span style='dispaly:none;'  id='cur'>".$user_profile['first_name'] . " " . $user_profile['last_name']." </span>";
       }
         

      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl(); 
        echo 'Please <a href="' . $login_url . '">Click To login.</a>';
        echo($e->getType());
        echo($e->getMessage());
      }   
    } else {
      //echo  "<span id='cur'> No user Found </span>";
      // No user, print a link for the user to login
      $login_url = $facebook->getLoginUrl();
      echo 'Please <a href="' . $login_url . '">login.</a>';
    }
    	
	} 
       
}